﻿using MQ.Core.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace MQ.Core.Db
{
    public interface IBaseDb
    {
        #region base
        string GetConnectionString();
        #endregion

        #region  查询数据
        bool Exist(string sql);
        bool Exist(string sql, object param = null);
        T GetObject<T>(string sql);
        Task<T> GetObjectAsync<T>(string sql);
        T GetObject<T>(string sql, object param = null);
        Task<T> GetObjectAsync<T>(string sql,object param=null);
        T GetEntity<T>(string sql);
        Task<T> GetEntityAsync<T>(string sql, object param = null);
        T GetEntity<T>(string sql, object param = null);
        IEnumerable<T> GetList<T>(string sql);
        Task<IEnumerable<T>> GetListAsync<T>(string sql);
        Task<IEnumerable<T>> GetListAsync<T>(string sql, object param = null);
        IEnumerable<T> GetList<T>(string sql, object param = null); 
        IEnumerable<T> GetList<T>(string sql, Pagination pagination, object param = null);
        Task<IEnumerable<T>> GetListAsync<T>(string sql, Pagination pagination, object param = null);
        DataTable GetList(string sql, object param = null);
        Task<DataTable> GetListAsync(string sql, object param = null);
        Task<DataTable> GetListAsync(string sql, Pagination pagination, object param = null);
        DataTable GetList(string sql, Pagination pagination, object param = null);
        #endregion

        #region  提交数据
        Task<int> ExecuteAsync(string sql, object param = null);
        int Execute(string sql, object param = null);
        int ExecuteProc(string sql, object param = null);
        Task<int> ExecuteProcAsync(string sql, object param = null);
        int Insert<T>(T entity) where T : class;
        Task<int> InsertAsync<T>(T entity) where T : class;
        int Update<T>(T entity) where T : class;
        Task<int> UpdateAsync<T>(T entity) where T : class;
        int Delete<T>(T entity) where T : class;
        Task<int> DeleteAsync<T>(T entity) where T : class;
        Task Transaction(Action action);
        IEnumerable<T> GetList<T>(Expression<Func<T, bool>> expression) where T: class;
        #endregion
    }
}
